package com.baijia.authentication.principal.credentials;

import com.baijia.authentication.AccountType;
import com.baijia.authentication.principal.Credentials;
import com.baijia.common.enums.UserRoleType;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

import javax.validation.constraints.NotNull;

/**
 * @title JigouCredentials
 * @desc 机构子帐号登录凭证
 * @author caoliang
 * @date 2015年12月8日
 * @version 1.0
 */
public class JigouCascadeAccountCredentials extends Credentials {

    private static final long serialVersionUID = -660845586228039498L;

    @NotNull
    private String username;

    @NotNull
    private String password;

    private boolean qrCode = false;

    public JigouCascadeAccountCredentials() {

    }

    public JigouCascadeAccountCredentials(String username, String password) {
        this.username = username;
        this.password = password;
    }

    public JigouCascadeAccountCredentials(String username, String password, boolean qrCode) {
        this(username, password);
        this.qrCode = qrCode;
    }

    public final String getPassword() {
        return this.password;
    }

    public final void setPassword(final String password) {
        this.password = password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    public Integer getAccountType() {
        return AccountType.ORG_SUB_ACCT.getCode();
    }

    public boolean isQrCode() {
        return qrCode;
    }

    @Override
    public String toString() {
        return "JigouCascadeAccountCredentials [accountType=" + getAccountType() + ", username=" + username
            + ", password=****]";
    }

    @Override
    public boolean equals(final Object o) {
        return EqualsBuilder.reflectionEquals(this, o);
    }

    @Override
    public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this);
    }

    @Override
    public Integer getUserRole() {
        return UserRoleType.ORG.getId();
    }

}